package com.xiaotu.spider.guduo.pipeline;

import java.util.List;

import org.springframework.stereotype.Component;

import com.xiaotu.common.model.GuDuoDataModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.spider.APipeline;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
@Component("GuDuoDataRedisPipeline")
public class GuDuoDataRedisPipeline extends APipeline{

	@Override
	protected void doProcess(ResultItems resultItems, Task task) {
		List<GuDuoDataModel> guduoDataList = resultItems.get(GuDuoDataModel.class.getName()+"List");
        if (guduoDataList == null || guduoDataList.size() == 0)
            return;
        String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.GUDUO_DATA_YYYYMMDD);
        for (GuDuoDataModel guDuoDataModel : guduoDataList) {
        	cacheHandler.hSet(key, guDuoDataModel.getId(), guDuoDataModel);
        	cacheHandler.setCacheTimeout(key);
		}
	}
	
}
